package com.xyzwps.harbor.util.args;

import java.util.Collection;

/**
 * Utilities for doing argument validation in methods and constructors
 */
public final class Args {

    public static final class Collections {

        /**
         * Checks that the specified collection is NOT EMPTY.
         *
         * @param collection the string to check
         * @return {@code collection} if not empty
         * @throws EmptyCollectionException if {@code str} is empty
         * @apiNote This method does not check nullity of {@code collection}. Before you use
         * this method, you should check nullity by yourself, for example,
         * using {@link java.util.Objects#requireNonNull(Object)}
         */
        public static <T> Collection<T> requireNonEmpty(Collection<T> collection) {
            // TODO: 这返回的是个 Collection 该怎么搞
            if (collection.isEmpty()) throw new EmptyCollectionException();
            return collection;
        }
    }

    public static final class Integers {

        /**
         * Checks that the specified integer is NOT negative.
         *
         * @param i the integer to check
         * @return {@code i} if not negative
         * @throws NegativeIntegerException if {@code str} is blank
         */
        public static int requireNonNegative(int i) {
            if (i < 0) throw new NegativeIntegerException();
            return i;
        }
    }

    public static final class Strings {

        /**
         * Checks that the specified string is NOT BLANK.
         *
         * @param str the string to check
         * @return {@code str} if not blank
         * @throws BlankStringException if {@code str} is blank
         * @apiNote This method does not check nullity of {@code str}. Before you use
         * this method, you should check nullity by yourself, for example,
         * using {@link java.util.Objects#requireNonNull(Object)}
         */
        public static String requireNonBlank(String str) {
            if (str.isBlank()) throw new BlankStringException();
            return str;
        }
    }
}
